<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Plazas
 *
 * @author marcelo.diaz
 */
class Plazas extends Controller{

    function Plazas(){
      parent::Controller("plazas");
      $this->load->model("Plazas_Model");
    }

	function index()
	{
      $email = "ALL";
      $this->email->from('conocepunta@gmail.com');
      $this->email->to('conocepunta@gmail.com');
      $this->email->subject('Plazas access');
            
      $data['page_title'] = "Todas las plazas y parques de Punta Alta - Espacios verdes, ideales para disfrutar al aire libre.";
      $data['meta_description'] = '<meta name="description" content="ConocePunta - Punta Alta, Buenos Aires, Argentina - Todas las plazas y parques de Punta Alta - Espacios verdes, ideales para disfrutar al aire libre." />';      
      $output = $this->load->view('head_view', $data, true);
      
      $places = $this->Plazas_Model->_all();
      $navbar = $this->write_navbar();
      //iterate and parse places
      $output .= $navbar;
      $output .= "<div class='content centered'>";
      $output .= 	$this->write_custom_content($places);  
      $output .= 	$this->write_sidebar("parques plazas outdoor");
      $output .= "</div>"; 
      //---------MAP---------
      $output .= $this->write_map();
      $output .= $this->load->view('foot_view', "", true);
      $this->output->set_output($output);
      //$this->email->message($email);
      //$this->email->send();
    }

    /**
     * 
     * @param <String> $place: name of the place to be searched
     * @return <json>
     */
    function name($place){
      //to lowercase
      //$place = strtolower($place);
      $json = $this->Plazas_Model->get_place($place);
      header('Content-Type:application/json');
      echo json_encode($json);
    }

    function all(){
      $json = $this->Plazas_Model->get_all();
      header('Content-Type:application/json');
      //!!!
      echo json_encode($json);  
    }
	
    /**
     *
     * @param <String> $name: name of the place to be searched in CASE-SENSITIVE
     */
    function nombre($name = false){
      if ($name){
        $email = "[".$name."]";
        $this->email->from('conocepunta@gmail.com');
        $this->email->to('conocepunta@gmail.com');
        $this->email->subject('Plazas access');
                
        $navbar = $this->write_navbar();
        $name_replaced = str_replace("-", " ", $name);
        $data['page_title'] = $name_replaced." - Todas las plazas y parques de Punta Alta - Espacios verdes, ideales para disfrutar al aire libre.";
        $data['meta_description'] = '<meta name="description" content="'.$name_replaced.' - ConocePunta - Punta Alta, Buenos Aires, Argentina - Todas las plazas y parques de Punta Alta - Espacios verdes, ideales para disfrutar al aire libre." />';        
        $output = $this->load->view('head_view', $data, true);      

        $banner_adsense = '<div class="lheader"><script type="text/javascript"><!--
                                      google_ad_client = "pub-2113662635661393";
                                      
                                      google_ad_slot = "4418063429";
                                      google_ad_width = 728;
                                      google_ad_height = 90;
                                      //-->
                                      </script>
                                      <script type="text/javascript"
                                      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                                      </script></div>';
        
        $output .= $navbar.
                   "<div class='content slim-content centered' style='height:120px'>".
        				$banner_adsense.
                   "</div>";        
        
        $content = "";
        //$place = $this->Plazas_Model->_place(strtolower($name));
        $place = $this->Plazas_Model->get_place($name);
        if (!$place){
	      $places = $this->Plazas_Model->_all();	      
	      //iterate and parse places	      
	      $content .= "<div class='content centered'>".
	 	      			"<p class='ui-state-highlight' style='width:50%; padding:10px; text-align:center;'>No hemos podido encontrar <strong>$name</strong>.</p>";
	      $content .= 	$this->write_custom_content($places);  
	      $content .= 	$this->write_sidebar("parques plazas outdoor");
	      $content .= "</div>"; 	                	        
          $email .= "NOT FOUND";         
        } else{
          //parse place
          $content .= "<div class='content slim-content centered'>".
          				$this->write_specific_item($place).
          			  "</div>";
        }
        $output .= $content;
       
        $output .= $this->load->view('foot_view', "", true);
        $this->output->set_output($output);
        $this->email->message($email);
        //$this->email->send();
      }else{
        $this->index();
      }
    }
}
?>
